import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import {
  Card,
  Form,
  Table,
  Divider,
  Row,
  Col,
  Select,
  Button,
  Input,
  DatePicker,
  Modal,
  Radio,
  InputNumber,
} from 'antd';
import { getParamUrl } from '../../utils/formatDataSource';
const RadioGroup = Radio.Group;
@connect(({ studentMg3, classInfo3, loading }) => ({
  studentMg:studentMg3,
  classInfo:classInfo3,
  loading: loading.models.tag,
}))
@Form.create()
class StudentClassTimeAddFrom extends PureComponent {
  state = {
    checkVisible: false,
    subjectList: [],
  };
  componentDidMount() {
    this.initLoad();
  }
  initLoad = () => {
    const { dispatch } = this.props;
    // var params ={"pageNo":1};
    // this.loadData(params);
    dispatch({
      type: 'classInfo3/getSubjectList',
    }).then(() => {
      this.setState({
        subjectList: this.props.classInfo.subjectList,
      });
    });
  };

  subjectSelect = e => {
    this.setState({
      subject: e,
    });
  };
  render() {
    const Option = Select.Option;
    const FormItem = Form.Item;

    const { subjectList } = this.props.classInfo;
    const { getFieldDecorator } = this.props.form;
    const { visible, onCancel, onCreate } = this.props;
    const formItemLayOut = {
      labelCol: { span: 4 },
      wrapperCol: { span: 20 },
    };
    return (
      <Modal title="添加课时" visible={visible} okText="添加" onCancel={onCancel} onOk={onCreate}>
        <Form layout="vertical">
          <FormItem {...formItemLayOut} label="">
            {getFieldDecorator('type', {
              rules: [{ required: true, message: '请选择添加方式' }],
              initialValue: 1,
            })(
              <RadioGroup>
                <Radio value={1}>购买课时</Radio>
                <Radio value={2}>赠送课时</Radio>
              </RadioGroup>
            )}
          </FormItem>
          <FormItem {...formItemLayOut} label="科目">
            {getFieldDecorator('subject', {
              initialValue: '',
              rules: [{ required: true, message: '请选择科目' }],
            })(
              <Select onSelect={this.subjectSelect}>
                {subjectList.map((item, index) => {
                  return (
                    <Option key={index} value={item.code}>
                      {item.msg}{' '}
                    </Option>
                  );
                })}
              </Select>
            )}
          </FormItem>
          <FormItem {...formItemLayOut} label="1v1">
            {getFieldDecorator('oneByOne', { initialValue: 0 })(
              <InputNumber min={0} max={10000} span={24} />
            )}
          </FormItem>
          <FormItem {...formItemLayOut} label="vip 1v1">
            {getFieldDecorator('vipOneByOne', { initialValue: 0 })(
              <InputNumber min={0} max={10000} span={24} />
            )}
          </FormItem>
          <FormItem {...formItemLayOut} label="班课">
            {getFieldDecorator('classLesson', { initialValue: 0 })(
              <InputNumber min={0} max={10000} span={24} />
            )}
          </FormItem>
        </Form>
      </Modal>
    );
  }
}

export default StudentClassTimeAddFrom;
